﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NET4.Database.Repository;

namespace NET4.DataNET4.Repository
{
  public class OfferteRepository : BaseNET4Repository<Offerte, OfferteRepository>, IRepository<Offerte>
  {
    public OfferteRepository() : base() { }

    public Offerte Select(Int32 id)
    {
      return this.Table.Where(o => o.OfferteId == id).First();
    }

    public List<Offerte> List()
    {
      return this.Table.ToList();
    }

    public void Save(Offerte offerte)
    {
      if (offerte.OfferteId == 0)
      {
        this.Table.InsertOnSubmit(offerte);
      }

      this.DataContext.SubmitChanges();
    }

    public void Delete(Offerte offerte)
    {
      this.Table.DeleteOnSubmit(offerte);

      this.DataContext.SubmitChanges();
    }

    public IEnumerable<Offerte> ListByOfferRequestAndKind(OfferteAanvraag offerRequest, OfferteSoort offerKind)
    {
      if (offerKind == OfferteSoort.Opgegeven)
      {
        return this.Table.Where(o => o.OfferteAanvraagId == offerRequest.Id && o.PrijsPerStuk != 0);
      }
      else
      {
        return this.Table.Where(o => o.OfferteAanvraagId == offerRequest.Id && o.PrijsPerStuk == 0);
      }
    }
  }

  public enum OfferteSoort
  {
    Opgegeven,
    NietOpgegeven
  }
}
